﻿namespace FortuneUniverse.Fortune.Dyson
{
  public static class PlanetModelingManager
  {
    public static int[] veinProducts;
    public static int[] veinModelIndexs;
    public static int[] veinModelCounts;
    public static VeinProto[] veinProtos;

    public static PlanetAlgorithm Algorithm(PlanetData planet)
    {
      PlanetAlgorithm planetAlgorithm;
      switch (planet.algoId)
      {
        case 1:
          planetAlgorithm = (PlanetAlgorithm) new PlanetAlgorithm1();
          break;
        case 2:
          planetAlgorithm = (PlanetAlgorithm) new PlanetAlgorithm2();
          break;
        case 3:
          planetAlgorithm = (PlanetAlgorithm) new PlanetAlgorithm3();
          break;
        case 4:
          planetAlgorithm = (PlanetAlgorithm) new PlanetAlgorithm4();
          break;
        case 5:
          planetAlgorithm = (PlanetAlgorithm) new PlanetAlgorithm5();
          break;
        case 6:
          planetAlgorithm = (PlanetAlgorithm) new PlanetAlgorithm6();
          break;
        case 7:
          planetAlgorithm = (PlanetAlgorithm) new PlanetAlgorithm7();
          break;
        case 8:
          planetAlgorithm = (PlanetAlgorithm) new PlanetAlgorithm8();
          break;
        case 9:
          planetAlgorithm = (PlanetAlgorithm) new PlanetAlgorithm9();
          break;
        default:
          planetAlgorithm = (PlanetAlgorithm) new PlanetAlgorithm0();
          break;
      }
      planetAlgorithm?.Reset(planet.seed, planet);
      return planetAlgorithm;
    }

    public static void Start() => PlanetModelingManager.PrepareWorks();

    private static void PrepareWorks()
    {
      int length = 0;
      VeinProto[] dataArray = LDB.veins.dataArray;
      for (int index = 0; index < dataArray.Length; ++index)
        length = dataArray[index].ID + 1;
      PlanetModelingManager.veinProducts = new int[length];
      PlanetModelingManager.veinModelIndexs = new int[length];
      PlanetModelingManager.veinModelCounts = new int[length];
      PlanetModelingManager.veinProtos = new VeinProto[length];
      for (int index = 0; index < dataArray.Length; ++index)
      {
        PlanetModelingManager.veinProducts[dataArray[index].ID] = dataArray[index].MiningItem;
        PlanetModelingManager.veinModelIndexs[dataArray[index].ID] = dataArray[index].ModelIndex;
        PlanetModelingManager.veinModelCounts[dataArray[index].ID] = dataArray[index].ModelCount;
        PlanetModelingManager.veinProtos[dataArray[index].ID] = dataArray[index];
      }
    }
  }
}
